package com.ruoyi.oss.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ruoyi.common.core.domain.DataBaseEntity;
import lombok.*;
import org.hibernate.proxy.HibernateProxy;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Objects;

/**
 * oss文件存储
 *
 * @author xueyu
 */
@Getter
@Setter
@ToString
@AllArgsConstructor
@RequiredArgsConstructor
@Entity
@Table(name = "sys_oss")
@TableName(value = "sys_oss")
public class SysOss extends DataBaseEntity {

    private static final long serialVersionUID = 464854430198486771L;

    /**
     * 文件名称
     */
    @Column(name = "file_name")
    @TableField(value = "file_name")
    private String fileName;

    /**
     * oss中文件的全路径地址
     */
    @Column(name = "oss_path")
    @TableField(value = "oss_path")
    private String ossPath;

    /**
     * 原始名称
     */
    @Column(name = "original_name")
    @TableField(value = "original_name")
    private String originalName;

    /**
     * 文件的后缀
     */
    @Column(name = "file_suffix")
    @TableField(value = "file_suffix")
    private String fileSuffix;

    /**
     * 文件地址
     */
    @Column(name = "url")
    @TableField(value = "url")
    private String url;

    /**
     * oss服务商
     */
    @Column(name = "oss_service")
    @TableField(value = "oss_service")
    private String ossService;

    /**
     * 文件大小  byte
     */
    @Column(name = "file_size")
    @TableField(value = "file_size")
    private Long fileSize;

    /**
     * bucket桶的名称
     */
    @Column(name = "bucket_name")
    @TableField(value = "bucket_name")
    private String bucketName;

    @Override
    public final boolean equals(Object o) {
        if (this == o) return true;
        if (o == null) return false;
        Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass();
        Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass();
        if (thisEffectiveClass != oEffectiveClass) return false;
        SysOss sysOss = (SysOss) o;
        return getId() != null && Objects.equals(getId(), sysOss.getId());
    }

    @Override
    public final int hashCode() {
        return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
    }
}
